package com.nw.controller;

import com.auth0.jwt.exceptions.AlgorithmMismatchException;
import com.auth0.jwt.exceptions.SignatureVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.nw.service.TestService;
import com.nw.util.JWTUtils;
import com.sun.org.apache.xml.internal.utils.StringBufferPool;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.UUID;

/*
*
* 该Controller仅供测试使用
* 请勿连接
* */
@RestController
@RequestMapping("test")
public class TestController {
    @Resource
    TestService testService;
    @RequestMapping("test")
    public HashMap<String, Object> test1(String token){
        HashMap<String, Object> map = new HashMap<>();
        try {
            JWTUtils.verify(token);
            map.put("0","验证通过");
        } catch (TokenExpiredException e) {
            map.put("1","Token过期");
        } catch (SignatureVerificationException e){
            map.put("1","签名过期");
        } catch(AlgorithmMismatchException e) {
            map.put("1","加密算法不匹配");
        } catch (Exception e){
            e.printStackTrace();
            map.put("1","无效token");
        }
        return map;
    }

    @RequestMapping("test2")
    public HashMap<String, Object> test2() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("data","1111");
        return map;
    }

    //@Scheduled(cron = "0/5 * * * * *")
    @RequestMapping("test3")
    public String scheduledTask1(){
        System.out.println(testService.test());
        return testService.test();
    }


}
